﻿@{
    ViewBag.Title = "Member";
}
@section scripts
{
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script> 
    <script src="@Url.Content("~/Scripts/shared/shown.js")" type="text/javascript"></script>     
    <script src="@Url.Content("~/Scripts/common/export.js")" type="text/javascript"></script>
}
   <div class="mini-splitter" style="width:100%;height:100%;">
    <div size="270" showcollapseButton="true">
        @Html.Partial("~/Views/Modular/ToolbarTypeEx.cshtml")
        <div class="mini-fit">
           <ul id="tree1" class="mini-tree" style="width:100%;" expandOnLoad="0"
              textField="FName" idField="FItemID" parentField="FParentID" showTreeIcon="true" resultAsTree="false">        
           </ul>
        </div>
    </div>
       
    <div showCollapseButton="true">
        @Html.Partial("~/Views/Modular/ToolBarListInport.cshtml")
    <div id = "DivHeader">
        <table>
            <tr>
                <td width ="70px" align="right" style="padding-right:2px;">日期范围：</td>
                <td>
                    @Html.Partial("~/Views/Modular/dxDateRange.cshtml")
                </td>
                <td width ="120px" >
                    <input id="FDateType" name="FDateType" class="mini-combobox" style="width:120px;" TabIndex="1" value ="0" data ="dDateData"/> 
                </td>
                <td width ="80px" align="center">
                    <a class="mini-button" iconCls="icon-search" style="width:80px;" onclick="search" plain="true">查询</a>
                </td>
                <td width ="100px">
                    <a class="mini-button" name="exports" iconCls="icon-export" style="width:80px;" onclick="setExportExcel('datagrid1')" plain="true" visible="false">导出</a>
                </td>  
            </tr>
        </table>
        <table style="margin-bottom:4px;">
            <tr>
                <td width ="70px" height="30px" align="right">会员状态：</td>
                <td width ="150px" height="30px">
                    <input id="FDataType" name="FDataType" class="mini-combobox" style="width:150px;" TabIndex="1" value ="0" data ="dState"/>
                </td> 
                <td width="70px" height="30px" align="right">会员等级：</td>
                <td width="200px" height="30px">
                    @Html.Partial("~/Views/Modular/LookupMemberRank.cshtml")
                </td>
                <td width="70px" height="30px" align="right"><span class="abc">商户名称：</span></td>
                <td width="200px" height="30px">
                    <span class="abc">
                        @Html.Partial("~/Views/Modular/LookupCorpInfo.cshtml")
                    </span>
                </td>            
            </tr>
            <tr>
                <td width ="70px" height="30px" align="right" style="padding-right:5px;">会员搜索：</td>
                <td width ="150px" height="30px">
                    <input name="FNumber" class="mini-textbox" style="width:150px;"  onkeypress="setkeyPress()"/>
                </td>
                <td width ="70px" height="30px" align="right" style="padding-right:5px;">介绍人：</td>
                <td width ="200px" height="30px">
                    @Html.Partial("~/Views/Modular/LookupMember.cshtml")
                </td> 
                <td width="70px" height="30px" align="right">会员标签：</td>
                <td width="200px" height="30px">
                    <div id="TagComBox" name="TagComBox" class="mini-combobox" style="width:200px;" popupWidth="300" textField="FName" valueField="FItemID"
                         value="" multiSelect="true" showClose="true" oncloseclick="onCloseClick">
                        <div property="columns">
                            <div header="编号" width="30px" field="FItemID"></div>
                            <div header="标签" field="FName"></div>
                        </div>
                    </div>
                </td>
            </tr>
        </table>
    </div>

        <div class="mini-fit" >
            <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;" pageSize="15"
                    borderStyle="border:1;" url="../Member/GetMemberList" multiSelect="true"
                    allowCellSelect="true" allowCellEdit="true"showColumnsMenu="true"fitColumns="false"  
                    onrowdblclick="modify"  sortMode="client" onload="loaded">
                <div property="columns">
                    <div type="checkcolumn" ></div>
                    <div type="indexcolumn" width="40" headerAlign="center" >序号</div>
                    <div field="FClassName" name="FClassName" width="100" headeralign="center" allowsort="true">会员分类</div>
                    <div field="FNumber" name="FNumber" width="100" headeralign="center" allowsort="true">会员卡号</div>
                    <div field="FName" name="FName" width="120" headeralign="center" allowsort="true">会员姓名</div>
                    <div field="FPhone" name="FPhone" width="90" headeralign="center" allowsort="true">联系电话</div>
                    <div field="FPoint" name="FPoint" width="70" headeralign="center"  align="right" allowsort="true">当前积分</div>
                    <div field="FAmount" name="FAmount" width="70" headeralign="center"  align="right" allowsort="true" NumberFormat="#,0.00">当前余额</div>
                    <div field="FQty" name="FQty" width="70" headeralign="center"  align="right" allowsort="true" NumberFormat="#,0.00">剩余次数</div>
                    <div field="FDiscount" name="FDiscount" width="70" headeralign="center"  align="right" allowsort="true" NumberFormat="#,0.00">折扣</div>
                    <div field="FSheAmount" name="FSheAmount" width="70" headeralign="center"  align="right" allowsort="true"  NumberFormat="#,0.00">佘帐额度</div>
                    <div field="FRealAmt" name="FRealAmt" width="70" headeralign="center"  align="right" allowsort="true"  NumberFormat="#,0.00">本金结余</div>
                    <div field="FGiveAmt" name="FGiveAmt" width="70" headeralign="center"  align="right" allowsort="true"  NumberFormat="#,0.00">赠送结余</div>
                    <div field="FRankName" name="FRankName" width="80" headeralign="center" allowsort="true">会员等级</div>                    
                    <div field="FBirthday" name="FBirthday" width="80" headeralign="center" allowsort="true">会员生日</div>
                    <div field="FStartTime" name="FStartTime" width="80" headeralign="center" allowsort="true">生效日期</div>
                    <div field="FEndTime" name="FEndTime" width="80" headeralign="center" allowsort="true">失效日期</div>
                    <div field="FCreateTime" name="FCreateTime" width="80" headeralign="center" allowsort="true">注册日期</div>
                    <div field="FCorpNumber" name="FCorpNumber" width="80" headeralign="center" allowsort="true">商户编码</div>
                    <div field="FCorpName" name="FCorpName" width="120" headeralign="center" allowsort="true">商户名称</div>
                    <div field="fk_users_id" name="fk_users_id" width="80" headeralign="center" allowsort="true">电子会员ID</div>                    
                    <div field="FRemark" name="FRemark" width="120" headeralign="center" allowsort="true">备注</div>
                </div>
            </div>
        </div>
    </div>        
</div>

<script>

    var dState = [{ "id": "0", "text": "正常" }, { "id": "-2", "text": "停用" }];
    var dDateData = [{ "id": "0", "text": "不过滤" }, { "id": "1", "text": "按创建日期过滤" }, { "id": "2", "text": "按生日过滤" }];
    mini.parse();
    var grid = mini.get("datagrid1");
    var tree = mini.get("tree1");
    var dataList = [];
    function FormShown() {
        $.post("../corp/CorpIsOrg", { mjson: parent.window.getSystemAppID() }, function (data) {
            if (data == "-1") {
                $(".abc").hide();
            }
        });
        LoadListTree();
        tree.on("nodeselect", function (e) {
            LoadListData();
        });
        MemberTagLoad();
    }

    function loaded(e) {
        if (e.data.length == 0) {
            mini.getbyName("exports").set({ visible: false });
            mini.getbyName("import").set({ visible: false });
            return;
        }
        if (e.data[0].FExport == 1) {
            mini.getbyName("exports").set({ visible: true });
            mini.getbyName("import").set({ visible: true });
        }
        else {
            mini.getbyName("exports").set({ visible: false });
            mini.getbyName("import").set({ visible: false });
        }
    }

    function setkeyPress() {
        if (event.keyCode == 13)
            LoadListData();
    }
    //加载分类树
    function LoadListTree() {
        var sSystemAppID = parent.window.getSystemAppID();
        $.post('GetMemberClassTree', { mjson: sSystemAppID }, function (data) {
            tree.loadList(mini.decode(data));
            tree.select(0);
        });
    }

    function reLoadListTree() {
        var sSystemAppID = parent.window.getSystemAppID();
        var node = tree.getSelectedNode();
        $.post('GetMemberClassTree', { mjson: sSystemAppID }, function (data) {
            tree.loadList(mini.decode(data));
            //tree.expandAll(1);
            tree.selectNode(node);
        });
    }

    //加载资料列表
    function LoadListData() {
        var mNumber = mini.getbyName("FNumber").getValue();
        var mSonCorpID = mini.getbyName("FCorpItemID").getValue();
        var mRankId = mini.getbyName("FMemberRankID").getValue();
        var mDataType = mini.getbyName("FDataType").getValue();
        var sSystemAppID = parent.window.getSystemAppID();
        var date1 = mini.getbyName("FDate1").getFormValue();
        var date2 = mini.getbyName("FDate2").getFormValue();
        var mDateType = mini.getbyName("FDateType").getValue();
        var membertag = mini.getbyName("TagComBox").getSelecteds();
        var parentID = mini.getbyName("FMemberNumber").getValue();
        var tagList = "";
        for (var i = 0; i < membertag.length; i++) {
            if (tagList != "")
                tagList += ","
            tagList += membertag[i].FItemID;
        }
        var mload = tree.getData();
        if (mload.length > 0) {
            var node = tree.getSelectedNode();
            var classid = node.FItemID;
            var json = "[{";
            json = json + '"FSystemAppID":' + '"' + sSystemAppID + '",';
            json = json + '"mRankID":' + '"' + mRankId + '",';
            json = json + '"mClassID":' + '"' + classid + '",';
            json = json + '"mSonCorpID":' + '"' + mSonCorpID + '",';
            json = json + '"mParentID":' + '"' + parentID + '",';
            json = json + '"mDataType":' + '"' + mDataType + '",';
            json = json + '"mNumber":' + '"' + mNumber + '",';
            json = json + '"FDate1":' + '"' + date1 + '",';
            json = json + '"FDate2":' + '"' + date2 + '",';
            json = json + '"FCreateFlag":' + '"' + mDateType + '",';
            json = json + '"FMemberTag":' + '"' + tagList + '"';
            json = json + "}]";
            grid.load({ mydata: json });

            mExportDataUrl = grid.url;
            mExportDataJson = json;//mydata:mExportDataJson
        }
    }

    //搜索资料列表
    function search() {
        LoadListData();
    }

    ///增加分类
    function addClass() {
        var node = tree.getSelectedNode();
        mini.open({
            url: "../MemberClass/MemberClassInfo",
            title: "会员分类", width: 500, height: 550,
            onload: function () {
                var iframe = this.getIFrameEl();
                var data = {
                    action: "new", FClassID: node.FItemID, FClassNumber: node.FNumber, FClassName: node.FName,
                    FAuto: 0, FType: -1, FUpdateValue: 0
                };
                iframe.contentWindow.SetClassData(data);
            },
            ondestroy: function (action) {
                reLoadListTree();
            }
        });
    }

    ///增加资料
    function newBill() {
        var uID = parent.window.getSystemAppID();
        var node = tree.getSelectedNode();
        if (node.FItemID <= 0) {
            mini.alert("请选择一个分类再新增");
            return;
        }
        mini.open({
            url: "/Member/MemberInfo",
            title: "会员资料", width: 650, height: 450,
            onload: function () {
                var iframe = this.getIFrameEl();
                var data = {
                    action: "new", FItemID: "0", FClassID: node.FItemID, FClassNumber: node.FNumber,
                    FClassName: node.FName, FPointFlag: node.FPointFlag, FAmountFlag: node.FAmountFlag, FDiscount: node.FDiscount,
                    FSheAmount: node.FSheAmount, FSheFlag: node.FSheFlag
                };
                iframe.contentWindow.SetInfoData(data);
            },
            ondestroy: function (action) {
                grid.reload();
            }
        });
    }

    //修改分类
    function editClass() {
        var node = tree.getSelectedNode();
        if (node == null || node.FModifyFlag == 0) {
            mini.alert("选择分类不属于本商户不能修改");
            return;
        }
        mini.open({
            url: "../MemberClass/MemberClassInfo",
            title: "修改分类", width: 500, height: 550,
            onload: function () {
                var iframe = this.getIFrameEl();
                var data = {
                    action: "edit", FItemID: node.FItemID, FNumber: node.FNumber, FName: node.FName, FPointFlag: node.FPointFlag, FAmountFlag: node.FAmountFlag, FDiscount: node.FDiscount,
                    FTypeID: node.FTypeID, FCardType: node.FCardType, FDefault: node.FDefault, FAuto: node.FAuto, FType: node.FType, FUpdateValue: node.FUpdateValue, FSheFlag: node.FSheFlag,
                    FSheAmount: node.FSheAmount
                };
                iframe.contentWindow.SetClassData(data);
            },
            ondestroy: function (action) {
                reLoadListTree();
            }
        });
    }

    function resetpwd() {
        var row = grid.getSelected();
        if (row) {
            mini.confirm("确定重置密码？", "提示",
                function (action) {
                    if (action == "ok") {
                        $.post('/Member/Reset', { id: row.FItemID, mSystemAppID: parent.window.getSystemAppID() }, function (data) {
                            data = JSON.parse(data);
                            if (data.Status == 1) {
                                mini.alert("重置成功!");
                            } else {
                                mini.alert(data.msg);
                            }
                        });
                    }
                });
        } else {
            mini.alert("请选中一条记录");
        }
    }

    //修改资料
    function modify() {
        if (!mini.get("edit").getVisible()) return;
        var row = grid.getSelected();
        var node = tree.getSelectedNode();
        if (row.FModifyFlag == 0) {
            mini.alert("选择会员不属于本商户不能修改");
            return;
        }
        if (row.FItemID < 0) { return; }
        if (row) {
            mini.open({
                url: "/member/MemberInfo",
                title: "会员资料", width: 650, height: 450,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = {
                        action: "edit", FItemID: row.FItemID, FClassID: node.FItemID, FClassNumber: node.FNumber, FModifyFlag: row.FModifyFlag,
                        FClassName: node.FName, FPointFlag: node.FPointFlag, FAmountFlag: node.FAmountFlag, FRankID: row.FRankID
                    };
                    iframe.contentWindow.SetInfoData(data);
                },
                ondestroy: function (action) {
                    grid.reload();
                }
            });
        } else {
            mini.alert("请选中一条记录");
        }
    }

    function getDelJson() {
        var rows = grid.getSelecteds();
        var json = "[";
        for (var i = 0; i < rows.length; i++) {
            if (rows[i].FModifyFlag == 1) {
                if (i > 0) json = json + ',';
                js = '{"FItemID":' + rows[i].FItemID + '}';
                json = json + js
            }
        }
        json = json + "]";
        return json;
    }
    //删除资料
    function removeInfo() {
        var row = grid.getSelected();
        if (row == null || row.FModifyFlag == 0) {
            mini.alert("选择会员不属于本商户不能删除");
            return;
        }
        var FSystemAppID = parent.window.getSystemAppID();
        if (row) {
            mini.confirm("确定删除选中记录？", "提示",
                function (action) {
                    if (action == "ok") {
                        //var json = "{'FItemID':'" + row.FItemID + "'}";
                        var json = getDelJson();
                        $.post("RemoveInfo", { json: json, mSystemAppID: FSystemAppID }, function (data) {
                            var ret = mini.decode(data);
                            if (ret.status == 1) {
                                mini.showTips({ content: ret.msg, state: "success", x: "center", y: "top", timeout: 3000 });
                                grid.reload();
                            }
                            else {
                                mini.alert("" + ret.error);
                            }
                        });
                    }
                });
        } else {
            mini.alert("请选中一条记录");
        }
    }

    //删除分类
    function removeClass() {
        if (grid.getData().length > 0) {
            mini.alert("该分类有会员资料存在，不能删除！ ");
            return;
        }
        var tree = mini.get("tree1");
        var node = tree.getSelectedNode();
        if (node == null || node.FModifyFlag == 0) {
            mini.alert("选择分类不属于本商户不能删除");
            return;
        }
        var FSystemAppID = parent.window.getSystemAppID();
        if (node.FItemID > 0) {
            mini.confirm("确定要删除选中的记录吗？", "提示",
                function (action) {
                    if (action == "ok") {
                        var json = "{'FItemID':'" + node.FItemID + "'}";
                        $.post("../Member/RemoveMemberClass", { json: json, mSystemAppID: FSystemAppID }, function (data) {
                            var ret = mini.decode(data);
                            if (ret.status == 1) {
                                reLoadListTree();
                                mini.showTips({ content: ret.msg, state: "success", x: "center", y: "top", timeout: 3000 });
                            }
                            else {
                                mini.alert("" + ret.error);
                            }
                        });
                    }
                });
        } else {
            mini.alert("请选中一条记录");
        }
    }

    function editpwd() {
        var grid = mini.get("datagrid1");
        var row = grid.getSelected();
        if (row) {
            mini.open({
                url: "/Member/EditPwd",
                title: "密码修改", width: 430, height: 320,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = { action: "edit", FItemID: row.FItemID };
                    iframe.contentWindow.SetInfoData(data);
                },
                ondestroy: function (action) {
                    var grid = mini.get("datagrid1");
                    grid.reload();
                }
            });

        } else {
            mini.alert("请选中一条记录");
        }
    }

    function ExcelImport() {
        var FSystemAppID = parent.window.getSystemAppID();
        //console.log(FSystemAppID);
        mini.open({
            url: "../Data/Import.aspx?mDataType=8&mSystemAppID=" + FSystemAppID,
            title: "会员Excel导入", width: 500, height: 280
        });
    }

    function Batchset() {
        var grid = mini.get("datagrid1");
        var rows = grid.getSelecteds();
        if (rows.length > 0) {
            mini.open({
                url: "/Member/BatchSet",
                title: "批量设置", width: 700, height: 470,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = '';
                    for (var i = 0; i < rows.length; i++) {
                        if (rows[i].FModifyFlag == 1) {
                            if (i > 0) data += ',';
                            data += rows[i].FItemID;
                        }
                    }
                    iframe.contentWindow.SetInfoData(data);
                },
                ondestroy: function (action) {
                    grid.reload();
                }
            });
        }
        else {
            mini.alert("请选择会员进行批量设置");
        }
    }

    function MemberTagLoad() {
        var comBox = mini.get("TagComBox");
        comBox.load("MemberTagList?mSystemAppID=" + parent.window.getSystemAppID());
    }

    function onCloseClick(e) {
        var obj = e.sender;
        obj.setText("");
        obj.setValue("");
    }

</script>
